package com.ewili.x.special.service.data.impl;


import com.ewili.framework.utils.ObjectHttpClientUtils;
import com.ewili.x.special.service.data.inter.ExecsService;
import com.ewili.x.special.task.thread.inter.ExecsThreadTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author wonder
 */
@Slf4j
@Service
public class ExecsServiceImpl implements ExecsService {

    @Autowired
    private ExecsThreadTask execsThreadTask;

    @Override
    public void spideExecs() {
        String url = "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=GG&sty=GGMX&p=0&ps=100&js=var%20VoSqMrpn={pages:(pc),data:[(x)]}";
        Long pages = 0L;
        try {
            pages = ObjectHttpClientUtils.getEastMoneyJsonPages(url);
        } catch (Exception e) {
            log.error("url:{}", url, e);
        }
        if (pages == null || pages == 0) {
            return;
        }
        for (int i = 1; i <= pages; i++) {
            String doUrl = "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=GG&sty=GGMX&p=" + i + "&ps=100&js=var%20VoSqMrpn={pages:(pc),data:[(x)]}";
            execsThreadTask.spideExecs(doUrl);
        }

    }
}
